package core.properties;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * Description   : Functional Test Script
 * @author angel.tsvetkov
 */
public class PropertyReader
{
    public PropertyReader() {
        super();
    }

    public Properties read(File f) throws IOException {
        return read(new PropertyResourceBundle(new FileInputStream(f)));
    }
    
    public Properties read(ResourceBundle bundle) {
        Properties p = new Properties();
        Enumeration<?> keys = bundle.getKeys();

        while(keys.hasMoreElements() ) {
            String key = (String)keys.nextElement();
            
            if( !p.containsKey(key) ) {
                p.put(key, bundle.getString(key));
            }
        }
        return p;
    }

    public Properties read(String res) throws MissingResourceException {
    	return read(ResourceBundle.getBundle(res));
    }
}

